const axios = require('axios');
const request = require('request');
// console.log(axios);
// console.log(request);


let baseUrl = "https://www.1905.com"
let headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Connection": "keep-alive",
    "Host": "www.1905.com",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3776.400 QQBrowser/10.6.4212.400"
}


function myRequest(httpUrl) {
    return new Promise((resolve, reject) => {
        request.get(httpUrl, function (err, res, body) {
            if(err){
                reject("error")
            }
            resolve({res, body});
        })
    })
}


async function getClassUrl(){
    let httpUrl = "https://www.1905.com/mdb/film/search/"
    let {res, body} = await myRequest(httpUrl)

    console.log(res);
    let reg = /<dl class="srhGroup srhGroup85 clear">(.*?)<\/dl>/igs

    // 解析html内容
    let result = reg.exec(body)
    console.log(result[1])

    let reg01 = /<a(\s+)href="(.*?)"(\s+)title="(.*?)">(.*?)<\/a>/igs
    
    let result01 = [];
    let tmp;
    while(tmp = reg01.exec(result[1])){
        result01.push({
            url: baseUrl + tmp[2],
            name:tmp[5]
        })
    }
    console.log(result01)
}

getClassUrl()
